;;; guix-config --- additional software for a custom configuration of gnu-guix
;;; Copyright © 2020 Kolya <kolya.daemon@vfemail.net>
;;;
;;; This file is part of guix-config
;;;
;;; guix-config is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; guix-config is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (kolyad packages)
  #:use-module (guix gexp)
  #:use-module (guix monads)
  #:use-module (guix utils)
  #:use-module (gnu packages)
  #:export (%channel-root-directory
            %channel-patch-directory
            %channel-patch-path
            %channel-aux-directory
            %channel-aux-path

            search-channel-patch
            search-channel-patches

            computed-origin-method))


;;;
;;; Path Wizardry
;;;

;; XXX: This is a cludge, but the way Guix does it isn't very clean either.
(define %channel-root-directory
  (canonicalize-path (current-source-directory)))

(define %channel-aux-directory
  (make-parameter "/packages/aux-files/"))
(define %channel-aux-path
  (make-parameter
    (list (string-append %channel-root-directory (%channel-aux-directory)))))

(define %channel-patch-directory
  (make-parameter "/packages/patches/"))
(define %channel-patch-path
  (make-parameter
    (list (string-append %channel-root-directory (%channel-patch-directory)))))

(define (search-channel-patch file-name)
  (parameterize ((%patch-path (%channel-patch-path)))
    (search-patch file-name)))

(define-syntax-rule (search-channel-patches file-name ...)
  (list (search-channel-patch file-name) ...))


;;;
;;; Source Code processing.
;;;

(define* (computed-origin-method gexp-promise hash-algo hash
                                 #:optional (name "source")
                                 #:key (system (%current-system))
                                 (guile (default-guile)))
  "Return a derivation that executes the G-expression that results
from forcing GEXP-PROMISE."
  (mlet %store-monad ((guile (package->derivation guile system)))
    (gexp->derivation (or name "computed-origin")
                      (force gexp-promise)
                      #:graft? #f       ;nothing to graft
                      #:system system
                      #:guile-for-build guile)))

;;; vim: set expandtab tabstop=2 shiftwidth=2
;;; end of file packages.scm
